package com.ziyear.prometheus.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@Configuration
public class SecurityConfig {


    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .formLogin()
            .and()
            .httpBasic()
            .and()
            .authorizeRequests()
            //application-monitor为3小节本配置文件中自定义的actuator端点url，此处代码表示当访问actuator端点时，需要进行登录。用户名和密码参看3小节配置
            .antMatchers("/**/application-monitor/**").authenticated()
            .anyRequest().permitAll(); //其它业务接口不用登录
        return http.build();
    }
}
